package com.beta.resource.model;

import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;

import com.alibaba.fastjson.annotation.JSONField;
import com.beta.resource.utils.BaseString;

public class Metal {
    private static final int REQUEST_METHOD_MASK = 0xF00;
    public static final int REQUEST_METHOD_CREATE = 0x100;
    public static final int REQUEST_METHOD_DELETE = 0x200;
    public static final int REQUEST_METHOD_QUERY = 0x400;
    public static final int REQUEST_METHOD_UPDATE = 0x800;

    private static final int REQUEST_TYPE_MASK = 0xF0;
    // public static final int REQUEST_TYPE_TOKEN = 0x10;
    public static final int REQUEST_TYPE_VERSION = 0x20;
    public static final int REQUEST_TYPE_FILE = 0x40;
    public static final int REQUEST_TYPE_CMD = 0x80;

    public static final int RESPOND_MIME_TXT = 0x1;
    public static final int RESPOND_MIME_IMG = 0x2;
    public static final int RESPOND_MIME_CMD = 0x3;
    public static final int RESPOND_MIME_HTML = 0x8;

    public static final int PACKAGE_BODY_MAX_LENGTH = 128;

    @JSONField(name = "CMD")
    public int cmd = 0;
    @JSONField(name = "INDEX")
    public int index = 0;
    @JSONField(name = "SUID")
    public String suid = null;
    @JSONField(name = "MECHA")
    public String token = null;
    @JSONField(name = "BODY")
    public Object body = null;
    @JSONField(serialize = false)
    public int method = REQUEST_METHOD_QUERY;
    @JSONField(serialize = false)
    public int type = REQUEST_TYPE_VERSION;

    public void parse() {
        method = cmd & REQUEST_METHOD_MASK;
        type = cmd & REQUEST_TYPE_MASK;
    }

    public Metal copy(){
        Metal metal = new Metal();
        metal.suid = suid;
        metal.cmd = cmd;
        metal.index = index;
        metal.token = token;
        return metal;
    }

    public static Metal createNew(String suid){
        Metal metal = new Metal();
        metal.suid = suid;
        // metal.token = createToken();
        return metal;
    }

    public String toString(){
        return String.format("CMD:%d,SUID:%s,BODY:%s",cmd, suid, body);
    }
}
